﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Borton.Data;
using Borton.Beans;

namespace Borton
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private void Login_Load(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void loginButton_Click(object sender, EventArgs e)
        {
            String username = usernameField.Text;
            String password = passwordField.Text;

            if (DataAccess.login(username, password)) {
                initMainPanel();
            } else {
                MessageBox.Show("Incorrect username or password", "Login failed");
            }
        }

        private void initMainPanel() {
            ApplicationPanel p = new ApplicationPanel(new Bean[] {
                new Orszag(),
                new Felhasznalo()
            });
            p.FormClosed += new FormClosedEventHandler(this.applicationPanel_Closed);
            this.Hide();
            p.ShowDialog();
        }

        private void applicationPanel_Closed(object sender, EventArgs e)
        {
            this.Show();
        }
    }
}
